﻿using System.Net.Mail;

namespace Dexter.Domain.Model {
	public partial class EmailMessage {
		/// <summary>
		/// Converto the current instance to a new instance of <see cref="MailMessage"/>.
		/// </summary>
		/// <returns></returns>
		public virtual MailMessage ToMailMessage() {
			var msg = new MailMessage ( this.Sender , this.MailTo );
			msg.IsBodyHtml = true;

			if(this.Cc != null)
				msg.CC.Add ( this.Cc );

			if (this.Bcc != null)
				msg.Bcc.Add ( this.Bcc );

			msg.Subject = this.Subject;
			msg.Body = this.Body;

			return msg;
		}

		public virtual void UpdateStatusToFail() {
			this.Status = "Unable to send this message";
			this.RetryCount++;
		}
	}
}
